package com.cloudptt.api.models.lbs;

import java.io.UnsupportedEncodingException;

import com.cloudptt.api.comm.CheckData;

public class ReportData
{
	private long date = 0;
	private String num = null;
	private String name = null;
	private LocationData locData = null;
	private VitalData vitalData = null;
	
	
	public static ReportData getDefaultData()
	{
		LocationData locData = LocationData.getDefaultLocationData();
		VitalData vitalData = VitalData.getDefaultLocationData();
		return new ReportData("","",locData,vitalData);
	}

	public ReportData(long date,String dateStr)
	{
		this.date = date;
		if(dateStr != null
				&& dateStr.length() > 0)
		{
			String[] dataArr = dateStr.split(",");
			if(dataArr.length == 7)
			{
				this.num = "sip:" + dataArr[0] + "@mcptt.com";
				
				locData = new LocationData();
				String value = dataArr[1];
				double val = CheckData.parseDouble(value);
				locData.setLongitude(val);
				
				value = dataArr[2];
				val = CheckData.parseDouble(value);
				locData.setLattitude(val);
				
				vitalData = new VitalData();
				value = dataArr[3];
				long lVal = CheckData.parseLong(value);
				vitalData.setWorkHours(lVal);
				
				value = dataArr[4];
				int iVal = CheckData.parseInt(value);
				vitalData.setHeartRate(iVal);
			}
		}
 		
	}
	public ReportData(String num,String clientId,LocationData locData,VitalData vitalData)
	{
		this.num = num;
		this.name = clientId;
		this.locData = locData;
		this.vitalData = vitalData;
	}
	
	public void updateMcInfo(String num,String name) {
		this.num = num;
		this.name = name;
	}
	public VitalData getVitalData()
	{
		return vitalData;
	}

	public void setVitalData(VitalData vitalData)
	{
		this.vitalData = vitalData;
	}

	public long getDate()
	{
		return date;
	}

	public String getNum()
	{
		return num;
	}
	
	public String getName() {
		return name;
	}
	public void setLocData(LocationData locData)
	{
		this.locData = locData;
	}
	public LocationData getLocData()
	{
		return locData;
	}
	
	public String toString()
	{
		StringBuffer strBuff = new StringBuffer("ReportData :");
		strBuff.append("num = ").append(num);
		strBuff.append("name = ").append(name);
		
		strBuff.append("locData = ").append(locData);
		strBuff.append("vitalData = ").append(vitalData);
		
		return strBuff.toString();
	}
//	public String toString()
//	{
//		StringBuffer strBuff = new StringBuffer();
//		strBuff.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
//		strBuff.append("<location-info xmlns=\"urn:3gpp:ns:mcpttLocationInfo:1.0\">");
//		strBuff.append("<Report ");
//		
//		strBuff.append("TriggerId = \"").append(num).append("\"");
//		
//		strBuff.append(" ReportType=\"NonEmergency\">");
//		
//		if(locData != null)
//		{
//			strBuff.append(locData.toString());
//		}
//		
//		if(vitalData != null)
//		{
//			strBuff.append(vitalData.toString());
//		}
//		
//		strBuff.append("<ClientID>");
//		strBuff.append(name);
//		strBuff.append("</ClientID>");
//		
//		strBuff.append("</Report>");
//		strBuff.append("</location-info>");
//		
//		try {
//			return new String(strBuff.toString().getBytes(),"UTF-8");
//		} catch (UnsupportedEncodingException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
//		return strBuff.toString();
//	}
}
